/**
 *
 */
package picounit.java.file;

import java.io.File;

import picounit.java.Factory;
import picounit.java.type.Type;

class SourceRoot implements Factory<Type, File> {
    public SourceRoot(File sourceRoot) {
        this.sourceRoot = sourceRoot;
    }

    public Type create(File file) {
        return new Type(className(file, sourceRoot));
    }

    private String className(File classFile, File sourceRoot) {
        String relativeFileName =
            classFile.getAbsolutePath().substring(sourceRoot.getAbsolutePath().length() + 1);

        String extensionLessFileName =
            relativeFileName.substring(0, relativeFileName.length() - ".class".length());

        return extensionLessFileName.replace(File.separatorChar, '.');
    }

    private final File sourceRoot;
}